package com.systemdevelopment.mainproject.View.NormalUser;

import com.jfoenix.controls.JFXButton;
import com.systemdevelopment.mainproject.Model.Author;
import com.systemdevelopment.mainproject.Model.Book;
import com.systemdevelopment.mainproject.Model.BorrowRecord;
import com.systemdevelopment.mainproject.Model.Record;
import com.systemdevelopment.mainproject.View.PaneFactory;
import com.systemdevelopment.mainproject.View.mainUI;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;

import java.io.IOException;
import java.sql.SQLException;
import java.time.format.DateTimeFormatter;
import java.util.HashSet;

public class recordPane {
    private Pane linkPane;
    Pane getPane()
    {
        return linkPane;
    }
    recordPane(Record record)
    {
        FXMLLoader fxmlLoader = new FXMLLoader(recordPane.class.getResource("recordPane.fxml"));
        try {
            DateTimeFormatter dtf= DateTimeFormatter.ofPattern("yyyy-MM-dd"); //定义时间格式
            linkPane= fxmlLoader.load();
            Label title=(Label) linkPane.lookup("#title");
            title.setText(record.title);
            Label author=(Label) linkPane.lookup("#author");
            author.setText(record.author);
            author.setWrapText(true);
            Label rendtime=(Label) linkPane.lookup("#rendtime") ;
            rendtime.setText(record.starttime);
            Label returntime=(Label) linkPane.lookup("#returntime") ;
            returntime.setText(record.returntime);
            Label endtime=(Label) linkPane.lookup("#endtime") ;
            endtime.setText(record.endtime);
            JFXButton returnButton = (JFXButton) linkPane.lookup("#returnbutton") ;
            returnButton.setText("归还");
            if(!record.state.equals("未归还"))
                returnButton.setDisable(true);
            returnButton.setOnAction(event -> {
                try {
                    BorrowRecord.Return(mainUI.userController.getUser().getAccount(),record.ISBN);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
